#!/usr/bin/env python
# -*- coding:utf-8 -*-

import datetime

from django.shortcuts import render, redirect, HttpResponse
from web import models



def index(request):

    return render(request, 'web/index.html')


def price(request):
    """ 套餐 """
    # 获取套餐
    xftype = 1

    user_mobile_phone= request.session.get('user_mobile_phone', 0)  # 没有就user_id为0
        # 获取session中的user_id,如果用户登陆了，坑等有，如果没有登陆，就没有
    user_object = models.organization.objects.filter(mobile_phone=user_mobile_phone).first()
    if user_object :

            v = models.trade.objects.filter(org_id=user_object.org_id).filter(status="2").order_by(
                "-crdate").first()
            if v: # 有没有单子
                if v.end >= datetime.datetime.now():
                    xftype = "您的套餐未到期"
                    policy_list = [{"title": xftype, "price": "10/月", "id": 1},
                                   {"title": "套餐1", "price": "10/月", "id": 1},
                                   {"title": "套餐2", "price": "38/季", "id": 2},
                                   {"title": "套餐3", "price": "110/年", "id": 3}]
                    return render(request, 'web/price.html', {'policy_list': policy_list})

                else:
                    xftype = "您的套餐已过期"
                    policy_list = [{"title": xftype, "price": "10/月", "id": 1},
                                   {"title": "套餐1", "price": "10/月", "id": 1},
                                   {"title": "套餐2", "price": "38/季", "id": 2},
                                   {"title": "套餐3", "price": "110/年", "id": 3}]
                    return render(request, 'web/price.html', {'policy_list': policy_list})

            else:
                xftype = "请你选择合适的套餐"
                policy_list = [{"title": xftype, "price": "10/月", "id": 1},
                               {"title": "套餐1", "price": "10/月", "id": 1},
                               {"title": "套餐2", "price": "38/季", "id": 2},
                               {"title": "套餐3", "price": "110/年", "id": 3}]
                return render(request, 'web/price.html', {'policy_list': policy_list})



    else:
        xftype="多种方案，使用多种场景" #没登陆
        policy_list = [{"title": xftype, "price": "10/月", "id": 1}, {"title": "套餐1", "price": "10/月", "id": 1},
                       {"title": "套餐2", "price": "38/季", "id": 2}, {"title": "套餐3", "price": "110/年", "id": 3}]
        return render(request, 'web/price.html', {'policy_list': policy_list})






